Performing map iterations in a blockchain-based system

ABSTRACT

Disclosed herein are methods, systems, and apparatus, including computer programs encoded on computer storage media, for performing a map iteration by a network node of a blockchain network. One of the methods includes receiving a request to obtain a number of keys included in a map by the network node, the map storing a number of key-value pairs that include the number of keys and a number of values corresponding to the number of keys. The network node maintains data representing a forest that stores the number of keys that are stored in the map. The forest includes a number of trees, each tree includes up to a respective number of storage nodes, and each storage node stores a subset of the number of keys. The network node traverses the forest to retrieve the number of keys stored in the forest, and return the number of keys.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of PCT Application No.PCT/CN2019/123242, filed on Dec. 5, 2019, which is hereby incorporatedby reference in its entirety.

TECHNICAL FIELD

This specification relates to performing a map iteration, for example,in a blockchain-based system.

BACKGROUND

In context of computer science, a map is a data structure, which can beused to store a collection of key-value (kv) pairs and record themapping from keys to corresponding values/data objects. Maps areprovided in a variety of computer systems and can be designed to havepersistent features that allow simple and transparent read and write ofdisk data for developers, reducing development burden. A map iterationor traversal can be performed to retrieve keys and/or values of thekey-value pairs stored in the map. The map iteration typically involvesaccessing each of the key-value (kv) pairs stored in the map to retrievekeys and/or values sequentially. In some instances, certain applicationsor use cases in a blockchain system may require retrieving all keys orall values of the key-value pairs in the map, but not necessarily both.It would be desirable to develop a map iteration scheme to retrieve allthe keys or values in an efficient manner.

SUMMARY

Described embodiments of the subject matter can include one or morefeatures, along or in combination.

For example, in one embodiment, a network node of a blockchain networkreceives a request to obtain a number of keys included in a map. The mapstores a number of key-value pairs that include the number of keys and anumber of values corresponding to the number of keys. The network nodemaintains data representing a forest that stores the number of keys thatare stored in the map. The forest includes a number of trees, and eachtree include up to a respective number of storage nodes. Each storagenode stores a subset of the number of keys of the map. The network nodetraverses the forest to retrieve the number of keys stored in theforest, and return the number of keys.

In some embodiments, these general and specific aspects may beimplemented using a system, a method, or a computer program, or anycombination of systems, methods, and computer programs. The foregoingand other described embodiments can each, optionally, include one ormore of the following aspects:

In some embodiments, the network node traverses the forest by iteratingeach storage node of the forest and retrieving one or more keys that arestored in the each storage node of the forest.

In some embodiments, the network node traverses the forest by performinga depth-first search on the forest or a breadth-first search on theforest.

In some embodiment, each tree of the number of trees includes arespective number of levels, and each level include one or more storagenodes.

In some embodiments, the number of levels correspond to a number ofdifferent hash functions, and each key is stored in the forest based onone or more hash values of the key that are computed using one or morehash functions of the number of different hash functions.

In some embodiments, the network node receives a request to add a key ofa key-value pair to the forest in response to the key-value pair beingstored in the map. The network node determines a storage node of theforest to insert the key based on one or more hash values of the keythat are computed using one or more hash functions of the number ofdifferent hash functions, and stores the key to the storage node.

In some embodiments, the network node receives a request to delete a keyof a key-value pair from the forest in response to the key-value pairbeing deleted from the map. The network node determines a storage nodesof the forest that stores the key based on one or more hash values ofthe key that are computed using one or more hash functions of the numberof different hash functions, and deletes the key from the storage node.

In some embodiments, the network node receives more than one request toadd respective keys of key-value pairs to the forest in response to thekey-value pairs being stored in the map. The network node determinesdifferent storage nodes of the forest to insert the keys based on one ormore hash values of the keys that are computed using one or more hashfunctions of the number of different hash functions, and stores therespective keys to the different storage nodes.

In some embodiments, each tree of the number of trees includes a numberof leaf storage nodes and one or more non-leaf storage nodes, and eachof the one or more non-leaf storage nodes corresponds to a configurablenumber of child nodes.

In some embodiments, each storage node of the forest stores aconfigurable number of keys.

It is appreciated that methods in accordance with this specification mayinclude any combination of the aspects and features described herein.That is, methods in accordance with this specification are not limitedto the combinations of aspects and features specifically describedherein, but also include any combination of the aspects and featuresprovided.

The details of one or more embodiments of this specification are setforth in the accompanying drawings and the description below. Otherfeatures and advantages of this specification will be apparent from thedescription and drawings, and from the claims.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a diagram illustrating an example of an environment that canbe used to execute embodiments of this specification.

FIG. 2 is a diagram illustrating an example of an architecture inaccordance with embodiments of this specification.

FIG. 3 is a diagram illustrating an example of a blockchain-based systemfor performing a map iteration in accordance with embodiments of thisspecification.

FIG. 4 is a graph illustrating an example of a forest data structure inaccordance with embodiments of this specification.

FIG. 5 is a flowchart illustrating a process of performing a mapiteration that can be executed in accordance with embodiments of thisspecification.

FIG. 6 is a flowchart illustrating a process of key insertion that canbe executed in accordance with embodiments of this specification.

FIG. 7 is a flowchart illustrating a process of key deletion that can beexecuted in accordance with embodiments of this specification.

FIG. 8 is a diagram illustrating an example of modules of an apparatusin accordance with embodiments of this specification.

Like reference numbers and designations in the various drawings indicatelike elements.

DETAILED DESCRIPTION

This specification describes technologies for performing a map iterationto retrieve keys and/or values stored in a map. The map can be a datastructure that stores a number of key-value pairs that include a numberof keys and a number of values corresponding to the number of keys. Inthis specification, performing a map iteration can include operationsthat achieve a goal of the map iteration in returning keys and/or valuesstored in a map, without necessarily traversing the map itself. Forexample, technologies for performing a map iteration can includemaintaining a forest data structure that stores copies of the number ofkeys and/or values and traversing the forest data structure, instead ofthe map, to retrieve the number of keys and/or values in a moreefficient manner.

For conciseness, this specification describes techniques for performinga map iteration to retrieve the number of keys of the key-value pairsstored in the map. It would be understood by or apparent to a skilledartisan that the techniques can be applied to retrieve the number ofvalues or both the number of keys and the number of values of thekey-value pairs stored in the map, for example, by substituting the roleof keys with the corresponding values of keys and substituting the roleof keys with the corresponding key-value pairs, respectively.

The techniques described in this specification produce several technicaleffects. In some embodiments, separately from a map data structure (alsosimply referred to as a map) that store key-value pairs, a forest datastructure (also simply referred to as a forest) is introduced to storeall the keys of the key-value pairs that are stored in the map datastructure. The forest data structure can include multiple trees thatallow multiple simultaneous accesses of the forest data structure,enabling highly concurrent processing in a blockchain-based system. Forexample, the multiple tree configuration of the forest data structurecan enable multiple simultaneous or concurrent data access or otheroperations on the forest in parallel on respective trees of the forest.This can avoid a bottleneck of only a single-point data access andreduce a possibility of conflicting data accesses that might otherwiseoccur on a single tree or other serial or sequential data structure(e.g., a queue or an array). In some embodiments, the forest datastructure can use hash functions to distribute the keys in its storagenodes. The forest data structure can combine low complexity of the treestructure and a decentralized mapping function of the hash function toprovide low-latency, high-concurrency map iteration requests. In someembodiments, the described map iteration scheme can significantly reduceI/O complexity of key insertion and deletion. In some embodiments, thedescribed map iteration scheme provides configurable and customizablemulti-channel concurrency, data access/retrieval speed, and otherperformance metrics by configuring the parameters of the forest datastructure (e.g., the number of trees, the width and/or depth of eachtree). Accordingly, the described map iteration scheme can be used ortailored for various applications with improved overall systemperformance. For example, the described map iteration scheme can beimplemented in a smart contract in a blockchain-based system thatprovides configurable and customizable data retrieval services suitablefor one or more services provided by the blockchain-based system.

To provide further context for embodiments of this specification, and asintroduced above, distributed ledger systems (DLSs), which can also bereferred to as consensus networks (e.g., made up of peer-to-peer nodes),and blockchain networks, enable participating entities to securely, andimmutably conduct transactions, and store data. Although the termblockchain is generally associated with particular networks, and/or usecases, blockchain is used herein to generally refer to a DLS withoutreference to any particular use case.

A blockchain is a data structure that stores transactions in a way thatthe transactions are immutable. Thus, transactions recorded on ablockchain are reliable and trustworthy. A blockchain includes one ormore blocks. Each block in the chain is linked to a previous blockimmediately before it in the chain by including a hash of the previousblock. Each block also includes a local timestamp (e.g., provided by acomputing device that generates the block or a computing system thatmanages the blockchain), its own hash, and one or more transactions. Forexample, the block can include a block header and a block body. Theblock header can include the local timestamp, its own hash, and a hashof the previous block. The block body can include payload informationsuch as the one or more transactions (or transaction data). Thetransactions, which have already been verified by the nodes of theblockchain network, are hashed and encoded into a Merkle tree. A Merkletree is a data structure in which data at the leaf nodes of the tree ishashed, and all hashes in each branch of the tree are concatenated atthe root of the branch. This process continues up the tree to the rootof the entire tree, which stores a hash that is representative of alldata in the tree. A hash purporting to be of a transaction stored in thetree can be quickly verified by determining whether it is consistentwith the structure of the tree.

Whereas a blockchain is a decentralized or at least partiallydecentralized data structure for storing transactions, a blockchainnetwork is a network of computing nodes that manage, update, andmaintain one or more blockchains by broadcasting, verifying andvalidating transactions, etc. As introduced above, a blockchain networkcan be provided as a public blockchain network, a private blockchainnetwork, or a consortium blockchain network.

In general, a consortium blockchain network is private among theparticipating entities. In a consortium blockchain network, theconsensus process is controlled by an authorized set of nodes, which canbe referred to as consensus nodes, one or more consensus nodes beingoperated by a respective entity (e.g., a financial institution,insurance company). For example, a consortium of ten (10) entities(e.g., financial institutions, insurance companies) can operate aconsortium blockchain network, each of which operates at least one nodein the consortium blockchain network.

In some examples, within a consortium blockchain network, a globalblockchain is provided as a blockchain that is replicated across allnodes. That is, all consensus nodes are in perfect state consensus withrespect to the global blockchain. To achieve consensus (e.g., agreementto the addition of a block to a blockchain), a consensus protocol isimplemented within the consortium blockchain network. For example, theconsortium blockchain network can implement a practical Byzantine faulttolerance (PBFT) consensus, described in further detail below.

In some embodiments, a centralized ledger system can also adopt the datastructure of a blockchain to leverage immutability, reliability, andtrustworthiness of data stored on a blockchain. In some embodiments,such a centralized ledger system can be referred to as ablockchain-based centralized ledger system or a universal auditableledger service system. In some embodiments, the blockchain-basedcentralized ledger system can include a central trusted authority thatprovides transparent, immutable, and cryptographically verifiable datathat are stored in blocks of a blockchain data structure. The storeddata can be in a log format, including, for example, not only fortransaction logs but also other transaction data and block data. Due tothe existence of the central trusted authority, the blockchain-basedcentralized ledger system does not need to perform consensus processesto establish trust. In some embodiments, the blockchain-basedcentralized ledger system can be more efficient compared to a typicalblockchain-based distributed or decentralized ledger system. In someembodiments, the blockchain-based centralized ledger system can providea cloud-based storage service with enhanced trust, efficiency, andstorage performance.

In some embodiments, the centralized ledger system can be a node of ablockchain network. For example, the centralized ledger system can be anon-consensus node in the blockchain network and can provide highlyreliable and high-performance auditable streaming ledger services forthe consensus nodes or other non-consensus nodes in the blockchainnetwork, or entities outside of the blockchain network.

In some embodiments, the distributed ledger system (DLS) and theblockchain-based centralized ledger system can be collectively referredto a blockchain-based system. In other words, a blockchain-based systemis used to refer to and is broad enough to encompass a distributedledger system (DLS), a blockchain-based centralized ledger system, oranother system that adopts the data structure of a blockchain toleverage immutability, reliability, and trustworthiness of data storedon a blockchain.

FIG. 1 is a diagram illustrating an example of an environment 100 thatcan be used to execute embodiments of this specification. In someexamples, the environment 100 enables entities to participate in aconsortium blockchain network 102. The environment 100 includescomputing systems 106, 108, and a network 110. In some examples, thenetwork 110 includes a local area network (LAN), wide area network(WAN), the Internet, or a combination thereof, and connects web sites,user devices (e.g., computing devices), and back-end systems. In someexamples, the network 110 can be accessed over a wired and/or a wirelesscommunications link. In some examples, the network 110 enablescommunication with, and within the consortium blockchain network 102. Ingeneral the network 110 represents one or more communication networks.In some cases, the computing systems 106, 108 can be nodes of a cloudcomputing system (not shown), or each of the computing systems 106, 108can be a separate cloud computing system including a number of computersinterconnected by a network and functioning as a distributed processingsystem.

In the depicted example, the computing systems 106, 108 can each includeany appropriate computing system that enables participation as a node inthe consortium blockchain network 102. Examples of computing systemsinclude, without limitation, a server, a desktop computer, a laptopcomputer, a tablet computing device, and a smartphone. In some examples,the computing systems 106, 108 host one or more computer-implementedservices for interacting with the consortium blockchain network 102. Forexample, the computing system 106 can host computer-implemented servicesof a first entity (e.g., user A), such as a transaction managementsystem that the first entity uses to manage its transactions with one ormore other entities (e.g., other users). The computing system 108 canhost computer-implemented services of a second entity (e.g., user B),such as a transaction management system that the second entity uses tomanage its transactions with one or more other entities (e.g., otherusers). In the example of FIG. 1, the consortium blockchain network 102is represented as a peer-to-peer network of nodes, and the computingsystems 106, 108 provide nodes of the first entity, and second entityrespectively, which participate in the consortium blockchain network102.

FIG. 2 is a diagram illustrating an example of an architecture 200 inaccordance with embodiments of the specification. The example conceptualarchitecture 200 includes participant systems 202, 204, 206 thatcorrespond to Participant A, Participant B, and Participant C,respectively. Each participant (e.g., user, enterprise) participates ina blockchain network 212 provided as a peer-to-peer network includingmultiple nodes 214, at least some of which immutably record informationin a blockchain 216. Although a single blockchain 216 is schematicallydepicted within the blockchain network 212, multiple copies of theblockchain 216 are provided, and are maintained across the blockchainnetwork 212, as described in further detail herein.

In the depicted example, each participant system 202, 204, 206 isprovided by, or on behalf of Participant A, Participant B, andParticipant C, respectively, and functions as a respective node 214within the blockchain network. As used herein, a node generally refersto an individual system (e.g., computer, server) that is connected tothe blockchain network 212, and enables a respective participant toparticipate in the blockchain network. In the example of FIG. 2, aparticipant corresponds to each node 214. It is contemplated, however,that a participant can operate multiple nodes 214 within the blockchainnetwork 212, and/or multiple participants can share a node 214. In someexamples, the participant systems 202, 204, 206 communicate with, orthrough the blockchain network 212 using a protocol (e.g., hypertexttransfer protocol secure (HTTPS)), and/or using remote procedure calls(RPCs).

Nodes 214 can have varying degrees of participation within theblockchain network 212. For example, some nodes 214 can participate inthe consensus process (e.g., as miner nodes that add blocks to theblockchain 216), while other nodes 214 do not participate in theconsensus process. As another example, some nodes 214 store a completecopy of the blockchain 216, while other nodes 214 only store copies ofportions of the blockchain 216. For example, data access privileges canlimit the blockchain data that a respective participant stores withinits respective system. In the example of FIG. 2, the participant systems202, 204, and 206 store respective, complete copies 216′, 216″, and216′″ of the blockchain 216.

A blockchain (e.g., the blockchain 216 of FIG. 2) is made up of a chainof blocks, each block storing data. Examples of data include transactiondata representative of a transaction between two or more participants.Transaction data is used as an example of data record stored in theblockchain. Examples of a transaction can include, without limitation,exchanges of something of value (e.g., assets, products, services,currency). In some embodiments, one or more operations executed in theledger system can be stored as transaction data in the blockchain. Forexample, the transaction data can include one or more operations ormanipulations of data stored in the block chain, information (e.g.,timestamp information) obtained from an external resource, or anyappropriate data can be stored in a blockchain (e.g., documents, images,videos, audio). The transaction data is immutably stored within theblockchain. That is, the transaction data cannot be changed.

Before storing in a block, the transaction data is hashed. Hashing is aprocess of transforming the transaction data (provided as string data)into a fixed-length hash value (also provided as string data). It is notpossible to un-hash the hash value to obtain the transaction data.Hashing ensures that even a slight change in the transaction dataresults in a completely different hash value. Further, and as notedabove, the hash value is of fixed length. That is, no matter the size ofthe transaction data the length of the hash value is fixed. Hashingincludes processing the transaction data through a hash function togenerate the hash value. An example of a hash function includes, withoutlimitation, the secure hash algorithm (SHA)-256, which outputs 256-bithash values.

Transaction data of multiple transactions are hashed and stored in ablock. For example, hash values of two transactions are provided, andare themselves hashed to provide another hash. This process is repeateduntil, for all transactions to be stored in a block, a single hash valueis provided. This hash value is referred to as a Merkle root hash, andis stored in a header of the block. A change in any of the transactionswill result in change in its hash value, and ultimately, a change in theMerkle root hash.

Blocks are added to the blockchain through a consensus protocol.Multiple nodes within the blockchain network participate in theconsensus protocol, and perform work to have a block added to theblockchain. Such nodes are referred to as consensus nodes. PBFT,introduced above, is used as a non-limiting example of a consensusprotocol. The consensus nodes execute the consensus protocol to addtransactions to the blockchain, and update the overall state of theblockchain network.

In further detail, the consensus node generates a block header, hashesall of the transactions in the block, and combines the hash value inpairs to generate further hash values until a single hash value isprovided for all transactions in the block (the Merkle root hash). Thishash is added to the block header. The consensus node also determinesthe hash value of the most recent block in the blockchain (i.e., thelast block added to the blockchain). The consensus node also adds anonce value, and a timestamp to the block header.

In general, PBFT provides a practical Byzantine state machinereplication that tolerates Byzantine faults (e.g., malfunctioning nodes,malicious nodes). This is achieved in PBFT by assuming that faults willoccur (e.g., assuming the existence of independent node failures, and/ormanipulated messages sent by consensus nodes). In PBFT, the consensusnodes are provided in a sequence that includes a primary consensus node,and backup consensus nodes. The primary consensus node is periodicallychanged, Transactions are added to the blockchain by all consensus nodeswithin the blockchain network reaching an agreement as to the worldstate of the blockchain network. In this process, messages aretransmitted between consensus nodes, and each consensus nodes provesthat a message is received from a specified peer node, and verifies thatthe message was not modified during transmission.

In PBFT, the consensus protocol is provided in multiple phases with allconsensus nodes beginning in the same state. To begin, a client sends arequest to the primary consensus node to invoke a service operation(e.g., execute a transaction within the blockchain network). In responseto receiving the request, the primary consensus node multicasts therequest to the backup consensus nodes. The backup consensus nodesexecute the request, and each sends a reply to the client. The clientwaits until a threshold number of replies are received. In someexamples, the client waits for f+1 replies to be received, where f isthe maximum number of faulty consensus nodes that can be toleratedwithin the blockchain network. The final result is that a sufficientnumber of consensus nodes come to an agreement on the order of therecord that is to be added to the blockchain, and the record is eitheraccepted, or rejected.

In some blockchain networks, cryptography is implemented to maintainprivacy of transactions. For example, if two nodes want to keep atransaction private, such that other nodes in the blockchain networkcannot discern details of the transaction, the nodes can encrypt thetransaction data. An example of cryptography includes, withoutlimitation, symmetric encryption, and asymmetric encryption. Symmetricencryption refers to an encryption process that uses a single key forboth encryption (generating ciphertext from plaintext), and decryption(generating plaintext from ciphertext). In symmetric encryption, thesame key is available to multiple nodes, so each node can en-/de-crypttransaction data.

Asymmetric encryption uses keys pairs that each include a private key,and a public key, the private key being known only to a respective node,and the public key being known to any or all other nodes in theblockchain network. A node can use the public key of another node toencrypt data, and the encrypted data can be decrypted using other node'sprivate key. For example, and referring again to FIG. 2, Participant Acan use Participant B's public key to encrypt data, and send theencrypted data to Participant B. Participant B can use its private keyto decrypt the encrypted data (ciphertext) and extract the original data(plaintext). Messages encrypted with a node's public key can only bedecrypted using the node's private key.

Asymmetric encryption is used to provide digital signatures, whichenables participants in a transaction to confirm other participants inthe transaction, as well as the validity of the transaction. Forexample, a node can digitally sign a message, and another node canconfirm that the message was sent by the node based on the digitalsignature of Participant A. Digital signatures can also be used toensure that messages are not tampered with in transit. For example, andagain referencing FIG. 2, Participant A is to send a message toParticipant B. Participant A generates a hash of the message, and then,using its private key, encrypts the hash to provide a digital signatureas the encrypted hash. Participant A appends the digital signature tothe message, and sends the message with digital signature to ParticipantB. Participant B decrypts the digital signature using the public key ofParticipant A, and extracts the hash. Participant B hashes the messageand compares the hashes. If the hashes are same, Participant B canconfirm that the message was indeed from Participant A, and was nottampered with.

FIG. 3 is a diagram illustrating an example of a system 300 inaccordance with embodiments of this specification. The system 300implements a blockchain-based system for performing a map iteration. Asshown, the system 300 includes a user 302, a client terminal 304, anetwork 306 (e.g., the Internet), and a blockchain network 308 includinga number of network nodes (e.g., network node 310).

The client terminal 304 can include, for example, any suitable computer,module, server, or computing element programmed to perform methodsdescribed herein. A user 302 can access the blockchain network 308 usinga client terminal 304, e.g., a mobile phone, a personal computer, or anycomputing device that can connect to the network 306.

In some embodiments, each network node of the blockchain network 308 canbe a consensus node or a non-consensus node of a blockchain network. Insome embodiments, one or more of the network nodes can be associatedwith a computer server that maintains different types of data. In thisexample, network node 310 is associated with a computer server 314 thatmaintains one or more maps 316 and one or more forests 318. In someembodiments, each one of the maps 316 can store a collection ofkey-value pairs. In some embodiments, a map 316 can include any suitabledata type that can store key-values pairs, such as associative array,map, symbol table, or dictionary, etc.

In the depicted example, a map 316 can store a number of keys 320 and anumber of values 322 corresponding to the keys 320. In some embodiments,a key 320 can be used as an index or an identifier to locate or retrievethe corresponding value 322. In some examples, the key 320 can representone or more of a type, quantity, time, date, status, or anotherattribute of the corresponding value 322. As an example, the values 322may include numeric values associated with assets (e.g., monetary funds,short-term and long-term investments, receivables and prepayments,inventories, deferred expenses, intangible assets, biological assets andother assets) of an enterprise, a person, or any other suitableentities, and the keys 320 can be types, quantities, times, dates, andthe statuses associated with the assets, or vice versa.

In some embodiments, a user 302 can access the computer server 314associated with the network node 310 and perform various operations onthe key-value pairs in the maps 316 that are stored in the computerserver 314. In some embodiments, the operations can include an additionof a key-value pair to a map 316, a removal of a key-value pair from amap 316, a modification of an existing key-value pair in a map 316, anda lookup of a value associated with a particular key in a map 316, etc.

As noted, maps (e.g., maps 316) can be used to record the mapping fromkeys to values/data objects. They have the advantages of simplicity,flexibility and efficiency, and can be used in compilation of blockchainsmart contracts. Maps are provided in a variety of blockchainarchitectures. In blockchain systems, maps often have persistentfeatures that allow simple and transparent read and write of disk datafor developers, reducing development burden.

In some instances, after inserting data into the map, to retrieve a listof all keys or values stored in the map, each key-value pair in theentire map may need to be traversed, for example, using one or morebuilt-in functions of the map. This map iteration or traversal based onthe map data structure itself can be computationally intensive and timeconsuming.

In some embodiments, users or developers of the blockchain-based systemmay design their own map iteration scheme, for example, using a smartcontract. For example, a linked list or array can be used to store thekeys or values that are stored in the map. Each node of the linked listis used to record one or more keys, and the nodes are connected byone-way or two-way pointers.

In some embodiments, a forest data structure (e.g., forests 318) can beused to store the keys or values that are stored in the map. The forestdata structure can combine the low complexity of the tree structure andthe decentralized mapping function of the hash function to achieve alow-latency, high-concurrency map iteration scheme. For example,compared to the implementation of the linked lists, the map iterationscheme based on the forest can improve system throughput and executionefficiency. For example, if a single linked list is used for storing thekeys or values, the insertion point of the data (e.g., the key or value)tends to be a conflict point of concurrency. When multiple smartcontracts are called to perform insertion of data, only one smartcontract call can succeed, resulting in a de facto serial execution.Most of the other smart contract calls will fail and rollback can occur,resulting a large amount of system resources wasted, which may seriouslyaffect the output bandwidth of the entire system. Moreover, the mapiteration scheme based on the forest can support random access, whichthe structure of the linked list is not suitable for. For example, whenimplementing deletion (or random insertion for concurrency) using thelinked list, a linear iteration with an I/O complexity of O(n) may beneeded for traversing a whole linked list, and the stored keys need tobe compared one by one. This linear complexity may be unacceptable undernormal circumstances due to disk read and write. By contrast, the I/Ocomplexity of key insertion and deletion of the map iteration schemebased on the forest can be O(lg(n)), which significantly reduce thelatency.

In some embodiments, a forest data structure can include N trees, whereN is larger than 1. Each tree can include a number of storage nodesincluding leaf nodes and non-leaf nodes. In some embodiments, each treecan have a configurable width, W. For example, each non-leaf node of atree can have up to W child nodes (e.g., 2 child nodes, 8 child nodes,etc.). Each storage node (including leaf nodes and non-leaf nodes) canstore a subset of keys that are stored in a corresponding map. A storagenode can store up to L keys, for example, 512 keys, 1024 keys, etc. Insome embodiments, each tree can have a depth D. That is, each tree caninclude D levels, where each level can include one or more storagenodes. For example, a first level of a tree can include the root node ofthe tree, a second level of the tree can include the child nodes of theroot node, and a third level of the tree can include respective childnodes of the child nodes in the second level, and so on. In someembodiments, one or more of the parameters, N, L, W, or D can beconfigurable, for example, based on system throughput, concurrencyrequirement, latency tolerance, or other criteria.

In some embodiments, each key stored in the map can be stored to astorage node of a tree through a series of hash functions correspondingto the multiple levels of the tree. For example, a first level of thetree can correspond to a first hash function, a second level of the treecan correspond to a second hash function which can be different from thefirst hash function, and so on.

In some embodiments, when a key is inserted into a forest, a first levelhash function is used for determining a tree of the forest in which thekey is stored. If the root node of the tree still has storage space, thekey can be inserted in the root node. Otherwise, if the root node of thetree does not have available space, a second level hash function can beused to determine a storage node in the next level in which the key maybe stored. The mapping can continue until a storage node with availablespace is found in the tree. The key can then be stored in the storagenode that has available space and a counter of the storage node for keys(also referred to as a key counter) can be incremented by one.

The process of deleting keys from the forest can be similar to theinsertion of keys. In some examples, the hash functions can be used tolocate the corresponding tree and storage node that stores the key, andthe key can then be deleted from the storage node. For example, when akey is to be deleted from a forest, a first level hash function is usedfor determining a tree of the forest in which that key will be deleted.If the key can be found in the root node of the determined tree, the keycan be deleted from the root node. If the key is not found in the rootnode, a second level hash function can be used to determine a storagenode in the next level in which the key may be deleted. The process cancontinue until the key is found in a storage node of the forest. The keycounter of a storage node can be decremented by one when a key isdeleted from the storage node. In some embodiments, if the key counterof a storage node of a tree is below a certain threshold (which can beconfigurable), the tree may be reshaped or re-constructed, for example,by moving a certain number of keys from one or more leaf nodes of thetree to the storage node in an upper level. In some embodiments, if thekey counter of a storage node becomes zero, the storage node can bedeleted.

FIG. 4 is a graph 400 illustrating an example of a forest data structure400 in accordance with embodiments of this specification. The forestdata structure 400 can be used to implement the forests 318 of FIG. 3.In the depicted example, the forest 400 includes trees 410 and 430. Notethat the forest 400 is shown to include two trees for illustrativepurposes only. The forest 400 can include any suitable number of trees,for example, based on system throughput, concurrency requirement. Insome embodiments, the forest 400 can include N trees thus allowing Nconcurrent accesses of the forest 400.

The trees 410 and 430 each includes a root node 412 and 432respectively. The root nodes 412 and 432 each includes two child nodes.As shown, root node 412 has child nodes 414 and 416, and root node 432has child nodes 434 and 436. Note that the root nodes 412 and 432 areshown to include two child nodes for illustrative purposes only. Theroot nodes 412 and 432 can have any suitable number of child nodes. Asnoted, the number of child nodes, W, for a non-leaf node can beconfigurable, for example, based on latency tolerance and the overallstorage space of the tree. For example, given the same overall storagespace of the tree and the same storage space of each storage node, asmaller value of W can give rise to a lower latency in retrieving a keystored in the tree. In some embodiments, non-leaf nodes of differenttrees can have different numbers of child nodes. For example, the rootnode 412 can have a first number of child nodes, and the root node 432can have a second number of child nodes, where the second number isdifferent from the first number.

As shown, each one of the trees 410 and 430 includes three levels ofstorage nodes. The first level (“level 1”) includes the root nodes(e.g., node 412 and 432). The second level (“level 2”) includes childnodes of the root nodes (e.g., nodes 414, 416, 434, and 436). The thirdlevel (“level 3”) includes the leaf nodes (e.g., nodes 418, 420, 422,424, 438, 440, 442, and 444). In some embodiments, each level of storagenodes corresponds to a hash function that can be used for determining astorage location of a key in the forest. For example, a first hashfunction corresponding to level 1 can be used to determine which tree(e.g., tree 410 or 430) in the forest 400 that a key is stored in. Insome embodiments, the storage location of a key can be determined bycomputing a first hash value of the key using the first hash function,computing a first modulo value by performing a first modulo operation onthe first hash value (for example, with respect to the number of treesin the forest 400), and determining a tree to store the key based on thefirst modulo value.

Continuing with the above example, if it is determined that the rootnode (e.g., node 412 or 432) of the determined tree has available space,the key can then be stored in the root node of the determined tree. Ifit is determined that the root node of the determined tree does not haveavailable space, a second hash function corresponding to level 2 can beused to determine a child node of the root node of the determined treeto store the key. For example, the storage location of a key can bedetermined by computing a second hash value of the key using a secondhash function, computing a second modulo value by performing a secondmodulo operation on the second hash value (for example, with respect tothe number of child nodes the root node of the determined tree), anddetermining a child node of the root node to store the key based on thesecond modulo value. If the determined child node at level 2 does nothave available space for storing the key, the process can continue todetermine a storage node in next level to store the key until a storagenode that has available space is found.

In some embodiments, the hash functions that correspond to the levels ofthe trees can be different for different trees. For example, a hashfunction (e.g., hash12) that corresponds to the level 2 of the tree 410can be different from a hash function (e.g., hash32) that corresponds tothe level 2 of the tree 430. Similarly, a hash function (e.g., hash13)that corresponds to the level 3 of the tree 410 can be different from ahash function (e.g., hash33) that corresponds to the level 3 of the tree430, that is, (e.g., hash12). In this case, given a key, its storagelocation can be determined in a sequential manner, level by level, byfirst determining which tree the key is to be stored in based on thefirst hash function and the first modulo operation, and then determiningwhich storage node in the determined tree in which the key is to bestored based on the specific hash function corresponding to the level 2of the determined tree, and possibly the specific hash functioncorresponding to the level 3 of the determined tree after determiningwhich storage node in the level 2 of the determined tree in which thekey is to be stored.

In some embodiments, different trees may use the same hash function forthe same level. For example, each of the tree 410 and tree 430 can sharethe same hash function (e.g., hash2) that corresponds to the level 2 anda hash function (e.g., hash3) that corresponds to the level 3. In thiscase, given a key, its storage location can be determined by computingthree hash values of the key based on the three hash functions at once,without the sequential processing of first identifying which tree thekey is to be stored and then identifying a specific hash functioncorresponding to a lower level of the determined tree. For example, fora given key (e.g., k), three hash values (e.g., h1=hash1(k),h2=hash2(k), and h3=hash3(k)) can be calculated, wherein hash1 is thehash function that corresponds to the level 1 of the forest. Threerespective modulo operations can be performed on the three hash valuesto determine a target storage node of the key. In some embodiments, astorage location can be represented as a vector of length D, where D isthe depth of the forest or the total number of levels in the forest. Asan example, the storage location of the key k can be represented by[modulo(h1, N), modulo(h2, W2), modulo(h3, W3)], where N is the numberof trees in the forest, W2 is the width of the tree in level 2, and W3is the width of the tree in level 3. Based on the storage locationvector [modulo(h1, N), modulo(h2, W2), modulo(h3, W3)], the storage nodecan be identified, for example, as the (modulo(h3, W3)+1)th child nodein level 3 of the (modulo(h2, W2)+1)th child node in level 2 of the(modulo(h1, N)+1)th tree.

An example of a process of deleting a key from the forest 400 caninclude determining a storage location (e.g., the location of a storagenode of the forest 400) of the key in the forest 400 based on one ormore hash functions of the forest 400, for example, according to similartechniques described above in connection with the insertion process.After identifying the storage location of the key in the forest 400(e.g., the storage location vector), the key can be removed from thestorage node of the forest 400. In some embodiments, deleting a key fromthe forest 400 can be performed in a sequential manner, conversely to asequential insertion process. For example, a sequential deletion processcan include locating a tree of the forest 400 that stores the key basedon a first hash function corresponding to the first level of the forest400 and determining whether the root node of the tree stores the key. Ifthe key is found in the root node of the tree, the key can be removedfrom the root node. If the key is not found in the root node, a secondhash function can be used to locate a child node of the root node thatmay store the key. This process can continue until a storage node thatstores the key is found.

Using the above-described insertion process, the keys of a map can bestored in a forest and a correspondence between the map and the forestcan be established. As noted, the hash-based forest data structure(e.g., forest 318, 400) as described herein can be used for traversingor iterating over a map for retrieving the keys of the map. In someembodiments, this can be done by performing a traversal or iterationprocess on the forest corresponding to the map. In some embodiments, thetraversal or iteration process can include performing a depth-firstsearch on the forest or performing a breadth-first search on the forestto retrieve all the keys that are stored in the forest.

In some embodiments, the described map iteration scheme allowsmulti-thread concurrency, which effectively improves the overallperformance of the system. For example, multiple requests of insertionand/or deletion can be processed concurrently, where different trees andstorage nodes of the forest can be determined to insert or deleterespective keys. This can reduce concurrency conflicts and improve theoverall throughput of the system.

FIG. 5 is a signal flow illustrating an example of a process 500 thatcan be executed in accordance with embodiments of this specification.The signal flow represents a process 500 for performing a map iteration.For convenience, the process will be described as being performed by asystem of one or more computers, located in one or more locations, andprogrammed appropriately in accordance with this specification. Forexample, a blockchain-based system (e.g., the system 300 of FIG. 3),appropriately programmed, can perform the process. In some embodiments,the process 500 can be implemented in a smart contract in theblockchain-based system. For example, the process 500 can provideconfigurable and customizable data retrieval services suitable for oneor more services provided by the blockchain-based system.

At 502, a network node (e.g., network node 310) of a blockchain network(e.g., blockchain network 308) receives a request to obtain a number ofkeys (e.g., keys 320) included in a map (e.g., map 316). In someembodiments, the map can store a number of key-value pairs that includethe number of keys and a number of values (e.g., values 322)corresponding to the number of keys.

At 504, data representing a forest (e.g., forest 318 and 400) ismaintained. In some embodiments, the forest stores the number of keysthat are stored in the map. In some embodiments, maintaining datarepresenting a forest includes generating a forest data structure, inaddition to or separately from the map, to stores the number of keysthat are stored in the map. In some embodiments, maintaining datarepresenting a forest includes, for example, adding a new key into theforest in response to a corresponding key-value pair is stored in themap, deleting an existing key from the forest in response to acorresponding key-value pair is removed from the map, modifying anexisting key in the forest in response to a corresponding key-value pairis changed in the map, or other operations on data representing theforest.

In some embodiments, the forest includes a number of trees (e.g., trees410 and 430), where each tree includes up to a respective number ofstorage nodes (e.g., nodes 412-444). Each storage node can be configuredto store a subset of the number of keys of the map.

In some embodiments, each tree of the forest includes a respectivenumber of levels, where each level includes one or more storage nodes.In some embodiments, the levels of a tree correspond to a number ofdifferent hash functions. Each key in the map is stored in the forestbased on one or more hash values of the key that are computed using oneor more hash functions of the different hash functions.

In some embodiments, the network node can receive a request to add a keyof a key-value pair to the forest in response to the key-value pairbeing stored in the map. The network node can determine a storage nodeof the forest to insert the key based on one or more hash values of thekey that are computed using one or more hash functions of the pluralityof different hash functions, for example, according to the techniquesdescribed with respect to FIG. 4. Then the key can be stored to thedetermined storage node.

In some embodiments, the network node can receive a request to delete akey of a key-value pair from the forest in response to the key-valuepair being deleted from the map. The network node can determine astorage node of the forest that stores the key based on one or more hashvalues of the key that are computed using one or more hash functions ofthe plurality of different hash functions, for example, according to thetechniques described with respect to FIG. 4. Then the key can be deletedfrom the determined from the storage node.

In some embodiments, the network node can support multiple concurrentrequests to manipulate one or more keys in the map. For example, therequests can include, for example, one or more of a first request to adda first key of a first key-value pair to the forest in response to thefirst key-value pair being stored in the map, a second request to deletea second key of a second key-value pair from the forest in response tothe second key-value pair being removed from the map, or a third requestto modify a third key of a third key-value pair in the forest inresponse to the third key-value pair being changed in the map. Thenetwork node can determine respective storage nodes of the forest of thefirst key, the second key, and the third key based on one or more hashvalues of the respective keys that are computed using one or more hashfunctions of the forest. The different storage nodes of the respectivekeys (e.g., in different tress of the forest) allow concurrent accessand operations of the forest. The respective keys can be added, deleted,or modified to the different storage nodes accordingly. As an example,the network node can receive more than one request to add respectivekeys of key-value pairs to the forest in response to the key-value pairsbeing stored in the map. The network node can determine differentstorage nodes of the forest to insert the keys based on one or more hashvalues of the keys that are computed using one or more hash functions ofthe plurality of different hash functions. Then the respective keys canbe stored to the different storage nodes concurrently.

At 506, the forest is traversed to retrieve the number of keys stored inthe forest. In some embodiments, the traversing of the forest can beperformed by visiting each storage node of the forest and retrieving oneor more keys that are stored in the storage node of the forest. Theforest can be traversed according to any appropriate forest traversingor iteration algorithm. For example, the traversing the forest caninclude performing a depth-first search on the forest or performing abreadth-first search on the forest.

At 508, the number of keys that are retrieved are returned. In someembodiments, all keys that are stored in the forest can be retrieved andreturned to a user that requests the map iteration.

FIG. 6 is a signal flow illustrating an example of a process 600 thatcan be executed in accordance with embodiments of this specification.The signal flow represents a process 600 for performing a key insertionto a forest. For convenience, the process will be described as beingperformed by a system of one or more computers, located in one or morelocations, and programmed appropriately in accordance with thisspecification. For example, a blockchain-based system (e.g., the system300 of FIG. 3), appropriately programmed, can perform the process. Insome embodiments, the process 600 can be implemented in a smart contractin the blockchain-based system. For example, the process 600 can provideconfigurable and customizable data insertion or storage servicessuitable for one or more services provided by the blockchain-basedsystem.

At 602, a forest data structure (e.g., forest 318 and 400) is maintainedin a network node (e.g., network node 310) of a blockchain network(e.g., blockchain network 308). In some embodiments, the forest stores anumber of keys (e.g., keys 320) of a number of key-value pairs that arestored in a map (e.g., map 316). In some embodiments, the forest caninclude a number of trees (e.g., trees 410 and 430), where each tree caninclude a respective number of storage nodes. Each storage node isconfigured to store a subset of the number of keys of the map. In someembodiments, each of the number of trees includes a respective number oflevels, and each level corresponds to a respective hash function.

At 604, the network node receives a request to add a key of a key-valuepair into the forest. In some embodiments, the key-value pair is one ofthe key-value pairs that are stored in the map.

At 606, a first hash value of the key is computed using a first hashfunction. For example, for a given key (e.g., k), a first hash value ofthe key (e.g., h1) is computed using a first hash function (e.g.,hash1). That is, h1=hash1(k). In some embodiments, the first hashfunction corresponds to a first level of storage nodes of the forest. Insome embodiments, the first level of storage nodes of the forest includethe root nodes of the trees of the forest.

At 608, one of the number of trees to store the key is determined basedon the first hash value. In some embodiments, the determining of thetree to store the key can be performed by performing a modulo operationon the first hash value to generate a first modulo value and determiningthe one of the number of trees to store the key based on the firstmodulo value. In some embodiments, the modulo operation is a modulooperation relative to the number of trees in the forest (e.g., L). Forexample, the first modulo value (e.g., m1) can be obtained according to:m1=modulo (hash1(k), L). The first modulo value can have a value of 0,1, 2, . . . , L−1, which can correspond to the 1^(st), 2^(nd), 3^(rd), .. . , or the Lth tree in the forest.

At 610, the network node determines a target storage node of thedetermined tree to store the key. In some embodiments, the targetstorage node can be determined by determining whether the root node ofthe determined tree has available space for storing the key. If it isdetermined that the root node has available space for storing the key,the root node can be determined as the target storage node and the keycan be stored in the root node.

If it is determined that the root node does not have available space forstoring the key, the network node can compute a second hash value of thekey using a second hash function, where the second hash functioncorresponds to a second level of the determined tree. For example, for asecond hash value of the key (e.g., h2) is computed using a second hashfunction (e.g., hash2). That is, h2=hash2(k). The second hash functioncan be different from the first hash function. Then, the network nodecan determine a second storage node in the second level of determinedtree to store the key based on the second hash value. In someembodiments, the network node can perform a modulo operation on thesecond hash value to generate a second modulo value, and determines asecond storage node in the second level of the determined tree to storethe key based on the second modulo value. In some embodiments, themodulo operation is a modulo operation relative to the number of childnodes of the root node of the determined tree or a width of thedetermined tree (e.g., W). For example, the second modulo value (e.g.,m2) can be obtained according to: m2=modulo (hash2(k), W). The secondmodulo value can have a value of 0, 1, 2, . . . , W−1, which cancorrespond to the 1^(st), 2^(nd), 3^(rd), . . . or the Wth child node ofthe root node of the determined tree in the forest.

In some embodiments, the network node determines whether the secondstorage node has available space for storing the key. If it isdetermined that the second storage node has available space, the secondstorage node can be determined as the target storage node and the keycan be stored in the second storage node in the second level. If it isdetermined that the second storage node does not have available space,the network node can compute a third hash value of the key using a thirdhash function and determine the target storage node in the third levelbased on the third hash value. This process can continue until thetarget storage node is found.

At 612, the network node stores the key in the determined target storagenode. In some embodiments, the key counter of the target storage nodecan be incremented by one when a key is inserted in the target storagenode. In some embodiments, when the key counter of the target storagenode reaches a predetermined threshold (e.g., 1024 keys), the targetstorage node can be considered full and no more keys will be inserted tothe target storage node. In some embodiments, a new level (e.g., afourth level) can be added to the forest to add new storage nodes forstoring the key.

FIG. 7 is a signal flow illustrating an example of a process 700 thatcan be executed in accordance with embodiments of this specification.The signal flow represents a process 700 for performing a key deletionto a forest. For convenience, the process will be described as beingperformed by a system of one or more computers, located in one or morelocations, and programmed appropriately in accordance with thisspecification. For example, a blockchain-based system (e.g., the system300 of FIG. 3), appropriately programmed, can perform the process. Insome embodiments, the process 700 can be implemented in a smart contractin the blockchain-based system. For example, the process 700 can provideconfigurable and customizable data deletion or management servicessuitable for one or more services provided by the blockchain-basedsystem.

At 702, a forest data structure (e.g., forest 318 and 400) is maintainedin a network node (e.g., network node 310) of a blockchain network(e.g., blockchain network 308). In some embodiments, the forest stores anumber of keys (e.g., keys 320) of a number of key-value pairs that arestored in a map (e.g., map 316). In some embodiments, the forest caninclude a number of trees (e.g., trees 410 and 430), where each tree caninclude a respective number of storage nodes. Each storage node isconfigured to store a subset of the number of keys of the map. In someembodiments, each of the number of trees includes a respective number oflevels, and each level corresponds to a respective hash function.

At 704, the network node receives a request to delete a key of akey-value pair from the forest. In some embodiments, the key-value pairis one of the key-value pairs that are stored in the map.

At 706, a first hash value of the key is computed using a first hashfunction. For example, for a given key (e.g., k), a first hash value ofthe key (e.g., h1) is computed using a first hash function (e.g.,hash1). That is, h1=hash1(k). In some embodiments, the first hashfunction corresponds to a first level of storage nodes of the forest. Insome embodiments, the first level of storage nodes of the forest includethe root nodes of the trees of the forest.

At 708, one of the number of trees where the key is stored is determinedbased on the first hash value. In some embodiments, the determining ofthe tree where the key is stored can be performed by performing a modulooperation on the first hash value to generate a first modulo value anddetermining the one of the number of trees where the key is stored basedon the first modulo value. In some embodiments, the modulo operation isa modulo operation relative to the number of trees in the forest (e.g.,L). For example, the first modulo value (e.g., m1) can be obtainedaccording to: m1=modulo (hash1(k), L). The first modulo value can have avalue of 0, 1, 2, . . . , L−1, which can correspond to the 1^(st),2^(nd), 3^(rd), . . . , or the Lth tree in the forest.

At 710, the network node determines a target storage node of thedetermined tree where the key is stored. In some embodiments, the targetstorage node can be determined by determining whether the key can befound in the root node of the determined tree. If it is determined thatthe key can be found in the root node, the root node can be determinedas the target storage node and the key can be deleted from the rootnode.

If it is determined that the key cannot be found in the root node, thenetwork node can compute a second hash value of the key using a secondhash function, where the second hash function corresponds to a secondlevel of the determined tree. For example, for a second hash value ofthe key (e.g., h2) is computed using a second hash function (e.g.,hash2). That is, h2=hash2(k). In some embodiments, the second hashfunction can be different from the first hash function. Then, thenetwork node can determine a second storage node in the second level ofdetermined tree where the key may be stored based on the second hashvalue. In some embodiments, the network node can perform a modulooperation on the second hash value to generate a second modulo value,and determines a second storage node in the second level of thedetermined tree where the key may be stored based on the second modulovalue. In some embodiments, the modulo operation is a modulo operationrelative to the number of child nodes of the root node of the determinedtree or a width of the determined tree (e.g., W). For example, thesecond modulo value (e.g., m2) can be obtained according to: m2=modulo(hash2(k), W). The second modulo value can have a value of 0, 1, 2, . .. , W−1, which can correspond to the 1^(st), 2^(nd), 3^(rd), . . . orthe Wth child node of the root node of the determined tree in theforest.

In some embodiments, the network node determines whether the key can befound in the second storage node. If it is determined that the key canbe found in the second storage node, the second storage node can bedetermined as the target storage node and the key can be deleted fromthe second storage node in the second level. If it is determined thatkey cannot be found in the second storage node, the network node cancompute a third hash value of the key using a third hash function anddetermine the target storage node in the third level based on the thirdhash value. This process can continue until the key is found in thetarget storage node.

At 712, the network node deletes the key from the determined targetstorage node. In some embodiments, the key counter of the target storagenode can be decremented by one when a key is deleted from the targetstorage node. In some embodiments, if the key counter of the targetstorage node is below a certain threshold (which can be configurable),the tree where the target storage node is located may be reshaped orre-constructed, for example, by moving a certain number of keys from oneor more leaf nodes of the tree to the storage node in an upper level. Insome embodiments, if the key counter of a target storage node becomeszero, the target storage node can be deleted.

FIG. 8 is a diagram of an example of modules of an apparatus 800 inaccordance with embodiments of this specification. The apparatus 800 canbe an example of an embodiments of a blockchain node configured toperform a map iteration. The apparatus 800 can correspond to theembodiments described above, and the apparatus 800 includes thefollowing: a receiving module 802 that receives a request to obtain aplurality of keys included in a map by a network node, the map storing aplurality of key-value pairs that include the plurality of keys and aplurality of values corresponding to the plurality of keys; amaintaining module 804 that maintains data representing a forest thatstores the plurality of keys that are stored in the map, the forestincluding a plurality of trees, each tree including up to a respectiveplurality of storage nodes, each storage node storing a subset of theplurality of keys; a traversing module 806 that traverses the forest toretrieve the plurality of keys stored in the forest; and a returningmodule 808 that returns the plurality of keys.

In some embodiments, the apparatus 800 further includes: an iteratingsub-module that iterates each storage node of the forest; and aretrieving sub-module that retrieves one or more keys that are stored inthe each storage node of the forest.

In some embodiments, the traversing the forest includes at least one ofthe following: performing a depth-first search on the forest; orperforming a breadth-first search on the forest.

In some embodiments, each tree of the plurality of trees includes arespective plurality of levels, and wherein each level includes one ormore storage nodes.

In some embodiments, the plurality of levels correspond to a pluralityof different hash functions, and each key is stored in the forest basedon one or more hash values of the key that are computed using one ormore hash functions of the plurality of different hash functions.

In some embodiments, the apparatus 800 further includes: a receivingsub-module that receives a request to add a key of a key-value pair tothe forest in response to the key-value pair being stored in the map; adetermining sub-module that determines a storage node of the forest toinsert the key based on one or more hash values of the key that arecomputed using one or more hash functions of the plurality of differenthash functions; and a storing sub-module that stores the key to thestorage node.

In some embodiments, the apparatus 800 further includes: a receivingsub-module that receives a request to delete a key of a key-value pairfrom the forest in response to the key-value pair being deleted from themap; a determining sub-module the determines a storage nodes of theforest that stores the key based on one or more hash values of the keythat are computed using one or more hash functions of the plurality ofdifferent hash functions; and a deleting sub-module that deletes the keyfrom the storage node.

In some embodiments, the apparatus 800 further includes: a receivingsub-module that receives more than one request to add respective keys ofkey-value pairs to the forest in response to the key-value pairs beingstored in the map; a determining sub-module that determines differentstorage nodes of the forest to insert the keys based on one or more hashvalues of the keys that are computed using one or more hash functions ofthe plurality of different hash functions; and a storing sub-module thatstores the respective keys to the different storage nodes concurrently.

In some embodiments, each tree of the plurality of trees comprises aplurality of leaf storage nodes and one or more non-leaf storage nodes,and each of the one or more non-leaf storage nodes corresponds to aconfigurable number of child nodes.

In some embodiments, each storage node of the forest stores aconfigurable number of keys.

In some embodiments, the maintaining data representing a forest thatstores the plurality of keys that are stored in the map comprises one ormore of: generating a forest data structure to store the plurality ofkeys; adding a new key into the forest in response to a correspondingkey-value pair is stored in the map; deleting an existing key from theforest in response to a corresponding key-value pair is removed from themap; or modifying an existing key in the forest in response to acorresponding key-value pair is changed in the map.

The system, apparatus, module, or unit illustrated in the previousembodiments can be implemented by using a computer chip or an entity, orcan be implemented by using a product having a certain function. Atypical embodiment device is a computer (and the computer can be apersonal computer), a laptop computer, a cellular phone, a camera phone,a smartphone, a personal digital assistant, a media player, a navigationdevice, an email receiving and sending device, a game console, a tabletcomputer, a wearable device, or any combination of these devices.

For an embodiment process of functions and roles of each module in theapparatus, references can be made to an embodiment process ofcorresponding steps in the previous method. Details are omitted here forsimplicity.

Because an apparatus embodiment basically corresponds to a methodembodiment, for related parts, references can be made to relateddescriptions in the method embodiment. The previously describedapparatus embodiment is merely an example. The modules described asseparate parts may or may not be physically separate, and partsdisplayed as modules may or may not be physical modules, may be locatedin one position, or may be distributed on a number of network modules.Some or all of the modules can be selected based on actual demands toachieve the objectives of the solutions of the specification. A personof ordinary skill in the art can understand and implement theembodiments of the present application without creative efforts.

Referring again to FIG. 8, it can be interpreted as illustrating aninternal functional module and a structure of a blockchain-based mapiterating apparatus. The blockchain-based map iterating apparatus can bean example of a computer server associated with a blockchain networknode (e.g., computer server 314 associated with blockchain network node310). An execution body in essence can be an electronic device, and theelectronic device includes the following: one or more processors; andone or more computer-readable memories configured to store an executableinstruction of the one or more processors. In some embodiments, the oneor more computer-readable memories are coupled to the one or moreprocessors and have programming instructions stored thereon that areexecutable by the one or more processors to perform algorithms, methods,functions, processes, flows, and procedures as described in thisspecification. This specification also provides one or morenon-transitory computer-readable storage media coupled to one or moreprocessors and having instructions stored thereon which, when executedby the one or more processors, cause the one or more processors toperform operations in accordance with embodiments of the methodsprovided herein.

This specification further provides a system for implementing themethods provided herein. The system includes one or more processors, anda computer-readable storage medium coupled to the one or more processorshaving instructions stored thereon which, when executed by the one ormore processors, cause the one or more processors to perform operationsin accordance with embodiments of the methods provided herein.

Embodiments of the subject matter and the actions and operationsdescribed in this specification can be implemented in digital electroniccircuitry, in tangibly-embodied computer software or firmware, incomputer hardware, including the structures disclosed in thisspecification and their structural equivalents, or in combinations ofone or more of them. Embodiments of the subject matter described in thisspecification can be implemented as one or more computer programs, e.g.,one or more modules of computer program instructions, encoded on acomputer program carrier, for execution by, or to control the operationof, data processing apparatus. For example, a computer program carriercan include one or more computer-readable storage media that haveinstructions encoded or stored thereon. The carrier may be a tangiblenon-transitory computer-readable medium, such as a magnetic, magnetooptical, or optical disk, a solid state drive, a random access memory(RAM), a read-only memory (ROM), or other types of media. Alternatively,or in addition, the carrier may be an artificially generated propagatedsignal, e.g., a machine-generated electrical, optical, orelectromagnetic signal that is generated to encode information fortransmission to suitable receiver apparatus for execution by a dataprocessing apparatus. The computer storage medium can be or be part of amachine-readable storage device, a machine-readable storage substrate, arandom or serial access memory device, or a combination of one or moreof them. A computer storage medium is not a propagated signal.

A computer program, which may also be referred to or described as aprogram, software, a software application, an app, a module, a softwaremodule, an engine, a script, or code, can be written in any form ofprogramming language, including compiled or interpreted languages, ordeclarative or procedural languages; and it can be deployed in any form,including as a stand-alone program or as a module, component, engine,subroutine, or other unit suitable for executing in a computingenvironment, which environment may include one or more computersinterconnected by a data communication network in one or more locations.

A computer program may, but need not, correspond to a file in a filesystem. A computer program can be stored in a portion of a file thatholds other programs or data, e.g., one or more scripts stored in amarkup language document, in a single file dedicated to the program inquestion, or in multiple coordinated files, e.g., files that store oneor more modules, sub programs, or portions of code.

Processors for execution of a computer program include, by way ofexample, both general- and special-purpose microprocessors, and any oneor more processors of any kind of digital computer. Generally, aprocessor will receive the instructions of the computer program forexecution as well as data from a non-transitory computer-readable mediumcoupled to the processor.

The term “data processing apparatus” encompasses all kinds ofapparatuses, devices, and machines for processing data, including by wayof example a programmable processor, a computer, or multiple processorsor computers. Data processing apparatus can include special-purposelogic circuitry, e.g., an FPGA (field programmable gate array), an ASIC(application specific integrated circuit), or a GPU (graphics processingunit). The apparatus can also include, in addition to hardware, codethat creates an execution environment for computer programs, e.g., codethat constitutes processor firmware, a protocol stack, a databasemanagement system, an operating system, or a combination of one or moreof them.

The processes and logic flows described in this specification can beperformed by one or more computers or processors executing one or morecomputer programs to perform operations by operating on input data andgenerating output. The processes and logic flows can also be performedby special-purpose logic circuitry, e.g., an FPGA, an ASIC, or a GPU, orby a combination of special-purpose logic circuitry and one or moreprogrammed computers.

Computers suitable for the execution of a computer program can be basedon general or special-purpose microprocessors or both, or any other kindof central processing unit. Generally, a central processing unit willreceive instructions and data from a read only memory or a random accessmemory or both. Elements of a computer can include a central processingunit for executing instructions and one or more memory devices forstoring instructions and data. The central processing unit and thememory can be supplemented by, or incorporated in, special-purpose logiccircuitry.

Generally, a computer will also include, or be operatively coupled toreceive data from or transfer data to one or more storage devices. Thestorage devices can be, for example, magnetic, magneto optical, oroptical disks, solid state drives, or any other type of non-transitory,computer-readable media. However, a computer need not have such devices.Thus, a computer may be coupled to one or more storage devices, such as,one or more memories, that are local and/or remote. For example, acomputer can include one or more local memories that are integralcomponents of the computer, or the computer can be coupled to one ormore remote memories that are in a cloud network. Moreover, a computercan be embedded in another device, e.g., a mobile telephone, a personaldigital assistant (PDA), a mobile audio or video player, a game console,a Global Positioning System (GPS) receiver, or a portable storagedevice, e.g., a universal serial bus (USB) flash drive, to name just afew.

Components can be “coupled to” each other by being commutatively such aselectrically or optically connected to one another, either directly orvia one or more intermediate components. Components can also be “coupledto” each other if one of the components is integrated into the other.For example, a storage component that is integrated into a processor(e.g., an L2 cache component) is “coupled to” the processor.

To provide for interaction with a user, embodiments of the subjectmatter described in this specification can be implemented on, orconfigured to communicate with, a computer having a display device,e.g., a LCD (liquid crystal display) monitor, for displaying informationto the user, and an input device by which the user can provide input tothe computer, e.g., a keyboard and a pointing device, e.g., a mouse, atrackball or touchpad. Other kinds of devices can be used to provide forinteraction with a user as well; for example, feedback provided to theuser can be any form of sensory feedback, e.g., visual feedback,auditory feedback, or tactile feedback; and input from the user can bereceived in any form, including acoustic, speech, or tactile input. Inaddition, a computer can interact with a user by sending documents toand receiving documents from a device that is used by the user; forexample, by sending web pages to a web browser on a user's device inresponse to requests received from the web browser, or by interactingwith an app running on a user device, e.g., a smartphone or electronictablet. Also, a computer can interact with a user by sending textmessages or other forms of message to a personal device, e.g., asmartphone that is running a messaging application, and receivingresponsive messages from the user in return.

This specification uses the term “configured to” in connection withsystems, apparatus, and computer program components. For a system of oneor more computers to be configured to perform particular operations oractions means that the system has installed on it software, firmware,hardware, or a combination of them that in operation cause the system toperform the operations or actions. For one or more computer programs tobe configured to perform particular operations or actions means that theone or more programs include instructions that, when executed by dataprocessing apparatus, cause the apparatus to perform the operations oractions. For special-purpose logic circuitry to be configured to performparticular operations or actions means that the circuitry has electroniclogic that performs the operations or actions.

While this specification contains many specific embodiment details,these should not be construed as limitations on the scope of what isbeing claimed, which is defined by the claims themselves, but rather asdescriptions of features that may be specific to particular embodiments.Certain features that are described in this specification in the contextof separate embodiments can also be realized in combination in a singleembodiment. Conversely, various features that are described in thecontext of a single embodiments can also be realized in multipleembodiments separately or in any suitable subcombination. Moreover,although features may be described above as acting in certaincombinations and even initially be claimed as such, one or more featuresfrom a claimed combination can in some cases be excised from thecombination, and the claim may be directed to a subcombination orvariation of a subcombination.

Similarly, while operations are depicted in the drawings and recited inthe claims in a particular order, this should not be understood asrequiring that such operations be performed in the particular ordershown or in sequential order, or that all illustrated operations beperformed, to achieve desirable results. In certain circumstances,multitasking and parallel processing may be advantageous. Moreover, theseparation of various system modules and components in the embodimentsdescribed above should not be understood as requiring such separation inall embodiments, and it should be understood that the described programcomponents and systems can generally be integrated together in a singlesoftware product or packaged into multiple software products.

Particular embodiments of the subject matter have been described. Otherembodiments are within the scope of the following claims. For example,the actions recited in the claims can be performed in a different orderand still achieve desirable results. As one example, the processesdepicted in the accompanying figures do not necessarily require theparticular order shown, or sequential order, to achieve desirableresults. In some cases, multitasking and parallel processing may beadvantageous.

1. A computer-implemented method for performing a map iteration by anetwork node of a blockchain network, comprising: receiving a request toobtain a plurality of keys included in a map by the network node, themap storing a plurality of key-value pairs that comprise the pluralityof keys and a plurality of values corresponding to the plurality ofkeys; maintaining data representing a forest that stores the pluralityof keys that are stored in the map, the forest comprising a plurality oftrees, each tree comprising up to a respective plurality of storagenodes, each storage node storing a subset of the plurality of keys;traversing the forest to retrieve the plurality of keys stored in theforest; and returning the plurality of keys.
 2. The method of claim 1,wherein the traversing the forest to retrieve the plurality of keysstored in the forest comprises: iterating each storage node of theforest; and retrieving one or more keys that are stored in the eachstorage node of the forest.
 3. The method of claim 1, wherein thetraversing the forest comprises at least one of: performing adepth-first search on the forest; or performing a breadth-first searchon the forest.
 4. The method of claim 1, wherein each tree of theplurality of trees comprises a respective plurality of levels, andwherein each level comprises one or more storage nodes.
 5. The method ofclaim 1, wherein the plurality of levels correspond to a plurality ofdifferent hash functions, and wherein each key is stored in the forestbased on one or more hash values of the key that are computed using oneor more hash functions of the plurality of different hash functions. 6.The method of claim 5, wherein the method further comprises: receiving arequest to add a key of a key-value pair to the forest in response tothe key-value pair being stored in the map; determining a storage nodeof the forest to insert the key based on one or more hash values of thekey that are computed using one or more hash functions of the pluralityof different hash functions; and storing the key to the storage node. 7.The method of claim 5, wherein the method further comprises: receiving arequest to delete a key of a key-value pair from the forest in responseto the key-value pair being deleted from the map; determining a storagenodes of the forest that stores the key based on one or more hash valuesof the key that are computed using one or more hash functions of theplurality of different hash functions; and deleting the key from thestorage node.
 8. The method of claim 5, wherein the method furthercomprises: receiving more than one request to add respective keys ofkey-value pairs to the forest in response to the key-value pairs beingstored in the map; determining different storage nodes of the forest toinsert the keys based on one or more hash values of the keys that arecomputed using one or more hash functions of the plurality of differenthash functions; and storing the respective keys to the different storagenodes concurrently.
 9. The method of claim 1, wherein each tree of theplurality of trees comprises a plurality of leaf storage nodes and oneor more non-leaf storage nodes, and wherein each of the one or morenon-leaf storage nodes corresponds to a configurable number of childnodes.
 10. The method of claim 1, wherein each storage node of theforest stores a configurable number of keys.
 11. The method of claim 1,wherein maintaining data representing a forest that stores the pluralityof keys that are stored in the map comprises one or more of: generatinga forest data structure to store the plurality of keys; adding a new keyinto the forest in response to a corresponding key-value pair is storedin the map; deleting an existing key from the forest in response to acorresponding key-value pair is removed from the map; or modifying anexisting key in the forest in response to a corresponding key-value pairis changed in the map.
 12. A blockchain-based map iteration system,comprising: one or more processors; and one or more computer-readabledevices coupled to the one or more processors and having tangible,non-transitory, machine-readable media storing one or more instructionsthat, when executed by the one or more processors, perform operationscomprising: receiving a request to obtain a plurality of keys includedin a map by a network node, the map storing a plurality of key-valuepairs that comprise the plurality of keys and a plurality of valuescorresponding to the plurality of keys; maintaining data representing aforest that stores the plurality of keys that are stored in the map, theforest comprising a plurality of trees, each tree comprising up to arespective plurality of storage nodes, each storage node storing asubset of the plurality of keys; traversing the forest to retrieve theplurality of keys stored in the forest; and returning the plurality ofkeys.
 13. The system of claim 12, wherein the traversing the forest toretrieve the plurality of keys stored in the forest comprises: iteratingeach storage node of the forest; and retrieving one or more keys thatare stored in the each storage node of the forest.
 14. The system ofclaim 12, wherein the traversing the forest comprises at least one of:performing a depth-first search on the forest; or performing abreadth-first search on the forest.
 15. The system of claim 12, whereineach tree of the plurality of trees comprises a respective plurality oflevels, and wherein each level comprises one or more storage nodes. 16.The system of claim 12, wherein the plurality of levels correspond to aplurality of different hash functions, and wherein each key is stored inthe forest based on one or more hash values of the key that are computedusing one or more hash functions of the plurality of different hashfunctions.
 17. The system of claim 16, wherein the operations furthercomprise: receiving a request to add a key of a key-value pair to theforest in response to the key-value pair being stored in the map;determining a storage node of the forest to insert the key based on oneor more hash values of the key that are computed using one or more hashfunctions of the plurality of different hash functions; and storing thekey to the storage node.
 18. The system of claim 16, wherein theoperations further comprise: receiving a request to delete a key of akey-value pair from the forest in response to the key-value pair beingdeleted from the map; determining a storage nodes of the forest thatstores the key based on one or more hash values of the key that arecomputed using one or more hash functions of the plurality of differenthash functions; and deleting the key from the storage node.
 19. Thesystem of claim 16, wherein the operations further comprise: receivingmore than one request to add respective keys of key-value pairs to theforest in response to the key-value pairs being stored in the map;determining different storage nodes of the forest to insert the keysbased on one or more hash values of the keys that are computed using oneor more hash functions of the plurality of different hash functions; andstoring the respective keys to the different storage nodes concurrently.20. A non-transitory, computer-readable medium storing one or moreinstructions executable by a computer system to perform operationscomprising: receiving a request to obtain a plurality of keys includedin a map by a network node, the map storing a plurality of key-valuepairs that comprise the plurality of keys and a plurality of valuescorresponding to the plurality of keys; maintaining data representing aforest that stores the plurality of keys that are stored in the map, theforest comprising a plurality of trees, each tree comprising up to arespective plurality of storage nodes, each storage node storing asubset of the plurality of keys; traversing the forest to retrieve theplurality of keys stored in the forest; and returning the plurality ofkeys.